/// 错误状态码
class ErrorCode implements Code {
  /// 未知错误
  static const ErrorCode NETWORK_ERROR = const ErrorCode._init(-1, '未知错误');

  /// 网络超时
  static const ErrorCode NETWORK_TIMEOUT = const ErrorCode._init(-2, '网络超时');

  /// 网络连接错误
  static const ErrorCode NETWORK_CONNECT_ERROR =
      const ErrorCode._init(-3, '网络连接错误');

  /// 请求被取消
  static const ErrorCode NETWORK_CONNECT_CANCEL =
      const ErrorCode._init(-4, '请求被取消');

  /// 服务器端错误
  static const ErrorCode SERVER_ERROR = const ErrorCode._init(-5, '服务器端错误');

  /// 请求成功
  static const ErrorCode SUCCESS = const ErrorCode._init(2000, '请求成功');

  /// 未登录
  static const ErrorCode NETWORK_LOGOUT = const ErrorCode._init(401, '未登录');

  /// access_token无效
  static const ErrorCode TOKEN_INVALID =
      const ErrorCode._init(1010, 'access_token无效');

  /// refresh_token无效
  static const ErrorCode REFRESH_INVALID =
      const ErrorCode._init(1011, 'refresh_token无效');

  /// 根据token未获取到登录用户信息
  static const ErrorCode RE_LOGIN = const ErrorCode._init(1012, '请重新登录');

  final int _code;
  final String _msg;

  /// 状态码
  @override
  int get code => _code;

  /// 提示信息
  @override
  String get msg => _msg;

  const ErrorCode._init(this._code, this._msg);

  @override
  String toString() {
    return '{ "code": $_code, "msg": $_msg }';
  }
}

/// 返回约束
abstract class Code {
  int? get code;

  String? get msg;

  const Code();
}
